home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-09-02 | 10.6 KB | 290 lines | [TEXT/CCL2] |
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;; oou-utils.lisp
- ;;
- ;; Copyright © 1992 University of Toronto, Department of Computer Science
- ;; All Rights Reserved
- ;;
- ;; author: Mark A. Tapia markt@dgp.utoronto.ca or markt@dgp.toronto.edu
- ;;
- ;; Part of this code is from the oodles-of-utils package
- ;; with modifications for the traps to work under MCL2.0f2
- ;; and with support for color quickkdraw added.
- ;; Change history
- ;; 1992-05-13 added support for color window manager and macros for
- ;; saving a rectangular portion of the screen bit/pixmap,
- ;; executing any number of forms and then restoring the rectangular
- ;; bit/pixmap.
- ;;
- ;; 1992-05-22 compatability features added for MCL2.0f...
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
- (in-package menus)
- (export '(push-after with-wmgr-view queued-modal-dialog containing-view))
- (provide :oou-utils)
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;; GDevice-u.Lisp
- ;;
- ;; Copyright © 1991 Northwestern University Institute for the Learning Sciences
- ;; All Rights Reserved
- ;;
- ;; author: Michael S. Engber
- ;;
- ;; utilities for working with g-devices
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- (defun get-max-device (&optional globalRect)
- (if globalRect
- (#_GetMaxDevice :ptr globalRect)
- (with-dereferenced-handles ((GrayRgn_p (%get-ptr (%int-to-ptr #$GrayRgn))))
- (#_GetMaxDevice :ptr (pref GrayRgn_p :Region.rgnBBox)))))
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;; QuickDraw-u.lisp
- ;;
- ;; Copyright © 1991 Northwestern University Institute for the Learning Sciences
- ;; All Rights Reserved
- ;;
- ;; author: Michael S. Engber
- ;;
- ;; utilities for quickdraw
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
- (defmacro with-pen-state ((&key pnLoc pnSize pnMode pnPat pnPixPat) &body body)
- (let ((state (gensym)))
- `(rlet ((,state :PenState))
- (require-trap #_GetPenState :ptr ,state)
- (unwind-protect
- (progn
- ,@(when pnLoc `((require-trap #_MoveTo :long ,pnLoc)))
- ,@(when pnSize `((require-trap #_PenSize :long ,pnSize)))
- ,@(when pnMode `((require-trap #_PenMode :signed-integer ,pnMode)))
- ,@(when pnPat `((require-trap #_PenPat :ptr ,pnPat)))
- ,@(when pnPixPat `((require-trap #_PenPixPat :ptr ,pnPixPat)))
- ,@body)
- (require-trap #_SetPenState :ptr ,state)))))
-
- ;;;;;;;;;;
- ;;font macros
-
- (defmacro with-font-spec (font-spec &body body)
- (if (and (listp font-spec) (every #'constantp font-spec))
- (multiple-value-bind (ff ms) (font-codes font-spec)
- `(with-font-codes ,ff ,ms ,@body))
- (let ((ff (gensym))
- (ms (gensym)))
- `(multiple-value-bind (,ff ,ms) (font-codes ,font-spec)
- (with-font-codes ,ff ,ms ,@body)))))
-
- ;;;;;;;;;;
- ;;clip macros
-
- (defmacro with-clip-rgn (clip-rgn &body body)
- (let ((old-clip (gensym)))
- `(with-macptrs ((,old-clip (require-trap #_NewRgn)))
- (unwind-protect
- (progn
- (require-trap #_GetClip :ptr ,old-clip)
- (require-trap #_SetClip :ptr ,clip-rgn)
- ,@body)
- (require-trap #_SetClip :ptr ,old-clip)
- (require-trap #_DisposeRgn :ptr ,old-clip)))))
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;; end of quickdraw-u routines from oodles-of-utils
-
- ;;various patches that are standard in MCL2.0f...
- ;; From patches.lisp in the oodles-of-utils package
- #+mcl-final
- (defmacro pref (pointer accessor)
- `(rref ,pointer ,accessor :storage :pointer))
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;; simple-view-ce.Lisp
- ;;
- ;; Copyright © 1991 Northwestern University Institute for the Learning Sciences
- ;; All Rights Reserved
- ;;
- ;; author: Michael S. Engber
- ;;
- ;; methods for the view class
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
- ;; window manager
-
- (defclass WMgr-view (simple-view) ())
-
- (defmethod view-origin ((sv WMgr-view)) (declare (ignore sv)) #@(0 0))
-
- (defmethod view-clip-region ((sv WMgr-view))
- (declare (ignore sv))
- (#_SetRectRgn :ptr ccl::*simple-view-clip-region*
- :signed-integer -32768 :signed-integer -32768
- :signed-integer 32767 :signed-integer 32767)
- ccl::*simple-view-clip-region*)
-
- ;; Routine added to get the appropriate window manager port Markt
- (defun get-wmgrport ()
- (%get-ptr (%int-to-ptr (if *color-available*
- #$WMgrCPort ; colorQd window-manager
- #$WMgrPort ; old Qd window manager
- ))))
-
- (defmethod wptr ((sv WMgr-view))
- (if (pointerp (slot-value sv 'wptr))
- (slot-value sv 'wptr)
- (setf (slot-value sv 'wptr) (get-wmgrPort))))
-
- (defvar *WMgr-view*)
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;; end of routines from simple-view-ce.Lisp
-
- (defun init-wmgr ()
- (setq *WMGR-view* (make-instance 'WMgr-view))
- (wptr *wmgr-view*) ; access the window pointer field
- *wmgr-view*)
-
- (defun remove-wmgr ()
- (makunbound '*WMGR-view*))
-
- (defun get-wmgr ()
- (unless (and (boundp '*WMGR-view*)
- *wmgr-view*)
- (init-wmgr))
- *WMGR-view*)
-
- (defmacro with-wmgr-view (&body body)
- `(progn (get-wmgr)
- (with-focused-view *WMGR-view*
- ,@body
- )))
-
- (defmacro push-after (el list)
- ;; add the element to the end of the list
- `(setf ,list (nconc ,list (list ,el))))
-
- (defun check-wmgr ()
- ;; remove and then add #'init-wmgr to end of *lisp-startup-functions*
- (setq *lisp-startup-functions*
- (remove 'init-wmgr *lisp-startup-functions* :key #'function-name))
- (push-after #'init-wmgr *lisp-startup-functions*)
-
- ; remove and then add #'remove-wmgr to the front of the *save-exit-functions*
- (setq *save-exit-functions*
- (remove 'remove-wmgr *save-exit-functions* :key #'function-name))
- (push #'remove-wmgr *save-exit-functions*))
-
- (defun get-gport (view)
- ;; retrieves the underlying port-pixmap, and the two corners of
- ;; the port-rect for a view which possibly straddles screens
- (let ((port (wptr view)))
- (when port
- (let* ((port-rect (rref port :grafport.portrect))
- (screen-gdevice (get-max-device port-rect))
- (screen-top (rref screen-gdevice :gdevice.gdrect.topLeft))
- (screen-bottom (rref screen-gdevice :gdevice.gdrect.bottomRight))
- (port-pmap (rref screen-gdevice :gdevice.gdpmap)))
- (values port-pmap ; the screen pixmap
- screen-top ; the top left corner of the screen port rect
- screen-bottom ; the bottom right corner
- )))))
-
- ;; macros for saving/restoring screen pixmap images
- (defmacro safe-kill-picture (picture-var)
- `(progn
- (when (handlep ,picture-var)
- (kill-picture ,picture-var))
- (setq ,picture-var nil)))
-
- (defmacro with-saved-screen-map ((view clip-rect1 &key (saved-picture (gensym))
- keep) &rest body)
- ;; Executes the body which may change a portion of the screen within the
- ;; the clip-rection clip-rect1 rectangular portion of the screen
- ;; (expressed in global coordinates)
- ;; Within the body of the form, saved-picture is bound to the picture
- ;; corresponding to the clipped image of the bit map.
- ;; Upon normal or abnormal termination of the form, restores the screen image
- ;; and either deletes the saved-picture (default) or returns the saved-picture.
- ;; The value of the body is not returned.
- `(let (,saved-picture)
- (unwind-protect
- (progn
- (setq ,saved-picture (save-screen-map ,view ,clip-rect1))
- (with-clip-rect ,clip-rect1
- ,@body))
- (restore-screen-map ,saved-picture ,clip-rect1)
- (unless ,keep
- (safe-kill-picture ,saved-picture)))))
-
- (defun save-screen-map (view clip-rect1)
- ;; saves the portion of the screen corresponding to the global rectangle
- ;; clip-rect1 which overlaps the gdevice associated with the view
- (when (pointerp (wptr view))
- (multiple-value-bind (pixmap topLeft bottomRight)
- (get-gport view)
- (when pixmap
- (rlet ((r :rect :topLeft topLeft :bottomRight bottomRight))
- (intersect-rect clip-rect1 r r)
- (unless (empty-rect-p r)
- (let ((pict (#_OpenPicture :ptr clip-rect1)))
- (ccl::with-macptrs ((pixMap_h pixmap))
- (with-dereferenced-handles ((pixMap_p pixMap_h))
- (#_CopyBits :ptr pixmap_p
- :ptr pixmap_p
- :ptr clip-rect1
- :ptr clip-rect1
- :word 0 ;transfer mode
- :ptr (%null-ptr))
- (#_ClosePicture))
- pict))))))))
-
- (defun restore-screen-map (screen-picture clip-rect1)
- ;; restores the portion of the screen saved in the picture screen-picture
- ;; corresponding to the global rectangle clip-rect1
- (with-wmgr-view
- (when (handlep screen-picture)
- (#_DrawPicture :ptr screen-picture :ptr clip-rect1))))
-
-
- (check-wmgr) ; fix the startup and exit functions
- (init-wmgr) ; initialize the *wmgr-view*
-
- (defun queued-modal-dialog (window &optional (close-on-return t))
- "Similar to modal-dialog, but supports eval-enqueue actions"
- (unwind-protect
- (catch-cancel
- (loop
- while (and (WINDOW-SHOWN-P window) (wptr window))
- do (event-dispatch)
- (when *eval-queue*
- (loop
- while *eval-queue*
- do (eval (pop *eval-queue*))))))
- (when (and (wptr window) close-on-return)
- (window-close window))))
-
- #|
- ;; test the screen saver macro
- (defun box-point (dim)
- (make-point dim dim))
- (defun max-dim (point)
- (max (point-h point) (point-v point)))
- (defun test-screen-saver (topLeft bottomRight)
- (rlet ((r :rect :topLeft topLeft :bottomRight bottomRight))
-
- (let ((win (make-instance 'window :view-size #@(400 400) :view-position :centered)))
- (with-saved-screen-map (win r :saved-picture saved-picture) ; so we can use the saved-picture
- (window-select win)
- (with-wmgr-view
- (#_fillRect :ptr r :ptr *light-gray-pattern*))
- (with-port (wptr win)
- (#_drawPicture :ptr saved-picture :ptr r) ; draw the saved pixel map
- (sleep 1)))
- (sleep 1) ; show the restored portion of the screen
- (window-close win))))
- (test-screen-saver #@(0 0) #@(200 300))
-
- |#
-